﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityLayer;
using DataLayer.EF;
namespace DataLayer.CLASES_DAO
{
    public class clsTB_ListaOfacDAO
    {

        private BD_TRASNFINTEREntities ContextoDeObjs = new BD_TRASNFINTEREntities();
        public bool Insertar(TB_ListaOfac Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("TB_ListaOfac", Obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public bool Modificar(TB_ListaOfac obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("TB_ListaOfac", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;

            }
            return true;
        }
        public bool Eliminar(TB_ListaOfac obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("TB_ListaOfac", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public List<TB_ListaOfac> listar()
        {

            List<TB_ListaOfac> lista = new List<TB_ListaOfac>();
            try
            {
                var q = from c in ContextoDeObjs.TB_ListaOfac
                        select c;
                lista = q.ToList();

            }
            catch (Exception)
            {
            }
            return lista;
        } 
        public string listarGetOFAC(string detalle)
        {
           
            string output = "";
            List<TB_ListaOfac> lista = new List<TB_ListaOfac>();
            try
            {
                var q = from c in ContextoDeObjs.TB_ListaOfac
                        where  c.descripcionOFAC.Contains(detalle)
                        select c;
                lista = q.ToList();

                output = lista[0].codigoOFAC;

            }
            catch (Exception)
            {
            }
            return output;
        }
    }
}
